<%--
  Created by IntelliJ IDEA.
  User: Doris丶Lee
  Date: 2020-05-20
  Time: 07:05
  Description: 登录逻辑判断
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.*" %>

<%--设置字符集，转码--%>
<%
    request.setCharacterEncoding("utf-8");
%>

<%--实例化用户类和用户逻辑类--%>
<jsp:useBean id="loginUser" class="com.po.User" scope="page"/>
<jsp:useBean id="userDAO" class="com.dao.UserDao" scope="page"/>
<%--赋值：根据表单自动匹配--%>
<jsp:setProperty property="*" name="loginUser"/>

<%--调用业务逻辑代码--%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

    //如果用户和密码都等于admin,则登录成功
    if(userDAO.userLogin(loginUser))
    {
        session.setAttribute("loginUser", loginUser.getUsername());
        request.getRequestDispatcher("login_success.jsp").forward(request, response);

    }
    else
    {
        response.sendRedirect("login_failure.jsp");
    }
%>